package com.shawn.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shawn.dubbo.mapper.SettingsMapper;
import com.shawn.model.entity.Settings;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService //通过dubbo暴露服务
public class SettingsApiImpl implements SettingsApi {

    @Autowired
    private SettingsMapper settingsMapper;

    @Override
    public Settings getSettingsByUserId(Long userId) {
        LambdaQueryWrapper<Settings> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Settings::getUserId,userId);
        Settings settings = settingsMapper.selectOne(wrapper);
        return settings;
    }

    @Override
    public void update(Settings settings) {
        LambdaQueryWrapper<Settings> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Settings::getUserId,settings.getUserId());
        settingsMapper.update(settings,wrapper);
    }

    /**
     * 插入默认设置
     *
     * @param defaultSettings 默认设置
     */
    @Override
    public void insertDefaultSettings(Settings defaultSettings) {
        settingsMapper.insert(defaultSettings);
    }
}
